package com.example.cinema.mapper;

import com.example.cinema.entity.Schedule;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author yc138
 * @since 2024-08-26
 */
public interface ScheduleMapper extends BaseMapper<Schedule> {

    @Select("select * from schedule limit #{current},#{size}")
    @Results(id = "rm1", value = {
            @Result(column = "id", property = "id", id = true),
            @Result(column = "hid", property = "hid"),
            @Result(column = "mid", property = "mid"),
            @Result(column = "hid", property = "hall", one = @One(
                    select = "com.example.cinema.mapper.HallMapper.findAllByHid"
            )),
            @Result(column = "mid", property = "movie", one = @One(
                    select = "com.example.cinema.mapper.MovieMapper.selectById"
            ))
    })
    List<Schedule> findAllSchedule(@Param("current") int current, @Param("size") int size);

    @Select("select * from schedule where mid=#{mid} limit #{current},#{size}")
    @Results(id = "rm2", value = {
            @Result(column = "id", property = "id", id = true),
            @Result(column = "hid", property = "hid"),
            @Result(column = "mid", property = "mid"),
            @Result(column = "hid", property = "hall", one = @One(
                    select = "com.example.cinema.mapper.HallMapper.findAllByHid"
            )),
            @Result(column = "mid", property = "movie", one = @One(
                    select = "com.example.cinema.mapper.MovieMapper.selectById"
            ))
    })
    List<Schedule> findByMidSchedule(@Param("mid") int mid, @Param("current") int current, @Param("size") int size);

    @Select("select * from schedule where hid=#{hid} limit #{current},#{size}")
    @Results(id = "rm3", value = {
            @Result(column = "id", property = "id", id = true),
            @Result(column = "hid", property = "hid"),
            @Result(column = "mid", property = "mid"),
            @Result(column = "hid", property = "hall", one = @One(
                    select = "com.example.cinema.mapper.HallMapper.findAllByHid"
            )),
            @Result(column = "mid", property = "movie", one = @One(
                    select = "com.example.cinema.mapper.MovieMapper.selectById"
            ))
    })
    List<Schedule> findByHidSchedule(@Param("hid") int hid, @Param("current") int current, @Param("size") int size);

    @Select("select * from schedule where mid=#{mid} and hid=#{hid} limit #{current},#{size}")
    @Results(id = "rm4", value = {
            @Result(column = "id", property = "id", id = true),
            @Result(column = "hid", property = "hid"),
            @Result(column = "mid", property = "mid"),
            @Result(column = "hid", property = "hall", one = @One(
                    select = "com.example.cinema.mapper.HallMapper.findAllByHid"
            )),
            @Result(column = "mid", property = "movie", one = @One(
                    select = "com.example.cinema.mapper.MovieMapper.selectById"
            ))
    })
    List<Schedule> findByMidAndHidSchedule(@Param("mid") int mid, @Param("hid") int hid, @Param("current") int current, @Param("size") int size);

/////////
    @Select("select * from schedule where hid = #{hid}")
    @Results(id = "querySchedule", value = {
            @Result(column = "id", property = "id", id = true),
            @Result(column = "mid", property = "mid"),
            @Result(column = "mid", property = "movie", one = @One(
                    select = "com.example.cinema.mapper.MovieMapper.selectByIdlj"
            ))
    })
    Schedule querySchedule(int hid);

    @Select("select * from schedule where id=#{id}")
    @Results(id = "rm5", value = {
            @Result(column = "id", property = "id", id = true),
            @Result(column = "id", property = "id"),
            @Result(column = "hid", property = "hid"),
            @Result(column = "mid", property = "mid"),
            @Result(column = "hid", property = "hall", one = @One(
                    select = "com.example.cinema.mapper.HallMapper.findAllByHid"
            )),
            @Result(column = "mid", property = "movie", one = @One(
                    select = "com.example.cinema.mapper.MovieMapper.selectById"
            )),
            @Result(column = "id", property = "orders", many = @Many(
                    select = "com.example.cinema.mapper.OrderMapper.findByStu_id"
            ))
    })
    Schedule findByIdSchedule(@Param("id") int id);


    @Select("select * from schedule where id = #{id}")
    @Results(id = "rm6", value = {
            @Result(column = "id", property = "id", id = true),
            @Result(column = "hid", property = "hid"),
            @Result(column = "mid", property = "mid"),
            @Result(column = "hid", property = "hall", one = @One(
                    select = "com.example.cinema.mapper.HallMapper.findAllByHid"
            )),
            @Result(column = "mid", property = "movie", one = @One(
                    select = "com.example.cinema.mapper.MovieMapper.selectById"
            ))
    })
    Schedule findById(int id);

}
